using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.ComponentModel;
using Microsoft.Xna.Framework.Input;

namespace XnaGameComponents
{
    public class CharacterCamera : FreelookCamera
    {
        public CharacterCamera(Game game):base(game)
        {
        }

        Model model;
        private string modelPath;
        private Vector3[] modelOffset=new Vector3[3];

        public Vector3[] ModelOffset
        {
            get { return modelOffset; }
            set { modelOffset = value; }
        }


        public string Model
        {
            get { return modelPath; }
            set { modelPath = value; }
        }

        protected override void LoadContent()
        {
            base.LoadContent();
            model = new ContentManager(Game.Services).Load<Model>(modelPath);
        }

        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.View = View;
                    effect.Projection = Projection;
                    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(Position);
                }
                mesh.Draw();
            }
        }
    }
}
